/*
 * Copyright (c) 2023 fred
 * Licensed under the Apache License,Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
import { HtmlTreeBuilder } from '../parser/HtmlTreeBuilder';
import { Parser } from '../parser/Parser';
import { Document } from './Document';
import { Element } from './Element';
import { Node } from './Node';
import { OutputSettings } from './OutputSettings';

/**
 * Internal helpers for Nodes, to keep the actual node APIs relatively clean. A jsoup internal class, so don't use it as
 * there is no contract API).
 */
export class NodeUtils {
  /**
   * Get the output setting for this node,  or if this node has no document (or parent), retrieve the default output
   * settings
   */
  public static outputSettings(node: Node): OutputSettings {
    let owner = node.ownerDocument();
    return owner != null ? owner.getOutputSettings() : (new Document("")).getOutputSettings();
  }

  /**
   * Get the parser that was used to make this node, or the default HTML parser if it has no parent.
   */
  static parser(node: Node): Parser {
    let doc = node.ownerDocument();
    return (doc !== undefined && doc !== null) && (doc.getParser() !== undefined && doc.getParser() !== null) ? doc.getParser() : new Parser(new HtmlTreeBuilder());
  }

  /**
   This impl works by compiling the input xpath expression, and then evaluating it against a W3C Document converted
   from the original jsoup element. The original jsoup elements are then fetched from the w3c doc user data (where we
   stashed them during conversion). This process could potentially be optimized by transpiling the compiled xpath
   expression to a jsoup Evaluator when there's 1:1 support, thus saving the W3C document conversion stage.
   */
  // selectXpath(xpath:string,el:Element,nodeType:T)

}
